<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class UserAddress extends Model
{

    // 表名
    protected $name = 'user_address';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        'gender_text',
        'is_default_text'
    ];


    public function getGenderList()
    {
        return ['1' => __('Gender 1'), '0' => __('Gender 0')];
    }

    public function getIsDefaultList()
    {
        return ['1' => __('Is_default 1'), '0' => __('Is_default 0')];
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsDefaultTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_default']) ? $data['is_default'] : '');
        $list = $this->getIsDefaultList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user()
    {
        return $this->belongsTo('user', 'user_id')->setEagerlyType(0);
    }

    public function village()
    {
        return $this->belongsTo('village', 'village_id')->setEagerlyType(0);
    }
}
